<?php
/**
 * User: xzq
 * Date: 2018/8/7
 * Time: 9:02
 */

namespace app\library\model;
use think\Model;

class Reservation extends Model
{
    /**
     * 判断该座位是否有未完成的预约
     * @param $ids
     */
    public function isReservation($ids){
        if (is_array($ids)){
            $map['status'] = 0;
            $map['seatid'] = ['in',$ids];
            $map['startTime'] = ['>=',time()];
            $res = self::all($map);
            return $res ? $res : false;
        }
        $this->error = '参数传递错误';
        return false;
    }

    /**
     * 日座位统计
     * @param $map 区域与座位编号 
     */
    public function dTotal($map){
        $total = self::where($map)->whereTime('startTime', 'd')->count();
        return $total;
    }    
    /**
     * 周座位统计
     * @param $map 区域与座位编号 
     */
    public function wTotal($map){
        $total = self::where($map)->whereTime('startTime', 'w')->count();
        return $total;
    }    
    /**
     * 月座位统计
     * @param $map 区域与座位编号 
     */
    public function mTotal($map){
        $total = self::where($map)->whereTime('startTime', 'm')->count();
        return $total;
    }    
    /**
     * 年座位统计
     * @param $map 区域与座位编号 
     */
    public function yTotal($map){
        $total = self::where($map)->whereTime('startTime', 'y')->count();
        return $total;
    }
    /**
     * 总座位统计
     * @param $map 区域与座位编号 
     */
    public function total($map){
        $total = self::where($map)->count();
        return $total;
    }
}